package com.huawei.secure.android.common.detect;

import android.os.Build;
import android.os.Build.VERSION;
import android.util.Log;
import com.huawei.secure.android.common.detect.a.c;
import java.io.File;

public final class RootDetect {
    private static final String TAG = "RootDetect";
    private static final String h = "/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin:/system/bin/.ext:/system/sd/xbin:/system/usr/we-need-root:/cache:/data:/dev:/system/vendor/bin:/vendor/xbin:/system/vendor/xbin:/product/bin:/product/xbin:/data/local/tmp:/data/local/bin:/data/local/xbin:/data/local:/system/bin/failsafe";
    private static final String i = "su";
    private static final String j = "magisk";
    private static final String k = "busybox";

    private RootDetect() {
    }

    public static boolean isRoot() {
        if (VERSION.SDK_INT >= 27) {
            try {
                if (b.isRoot()) {
                    Log.e(TAG, "Emui 10, root exists");
                    return true;
                }
            } catch (Exception e) {
                Log.e(TAG, "isRoot exception : " + e.getMessage());
            }
            try {
                if (SD.irtj()) {
                    Log.e(TAG, "root exists");
                    return true;
                }
            } catch (Exception e2) {
                Log.e(TAG, "SD.irtj isRoot exception : " + e2.getMessage());
            }
        } else if (a()) {
            Log.e(TAG, "su file exists");
            return true;
        } else if (e()) {
            Log.e(TAG, "SecureProperty is wrong");
            return true;
        } else if (d()) {
            Log.i(TAG, "app run in emulator");
            return true;
        } else if (c()) {
            Log.i(TAG, "build.tags is wrong");
            return true;
        } else if (b()) {
            Log.e(TAG, "Magisk exists");
            return true;
        }
        return false;
    }

    private static boolean a() {
        return a(i);
    }

    private static boolean a(String str) {
        for (String str2 : h.split(":")) {
            if (new File(str2 + File.separator + str).exists()) {
                return true;
            }
        }
        return false;
    }

    private static boolean b() {
        return a(j);
    }

    private static boolean c() {
        String str = Build.TAGS;
        return str != null && str.contains("test-keys");
    }

    private static boolean d() {
        try {
            if (Build.HARDWARE.contains("goldfish") || Build.FINGERPRINT.contains("generic") || Build.MODEL.contains("google_sdk") || Build.MODEL.contains("Emulator") || Build.MODEL.contains("Android SDK built for x86") || Build.MODEL.contains("Android SDK built for arm64") || "google_sdk".equals(Build.PRODUCT)) {
                return true;
            }
            return false;
        } catch (Exception e) {
            Log.e(TAG, "Check emulator " + e.getMessage());
            return false;
        }
    }

    private static boolean e() {
        return "0".equals(c.e("ro.secure"));
    }
}
